package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

@Cmd(code = CrossProtocol.C_UNION_UPDATE_MEMBER_MAX_ABILITY, desc = "游戏服向商会跨服更新历史最高赚钱")
public class Cross2UpdateMemberMaxAbilityCmd extends CrossCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossUnionProto.CrossUnionUpdateHistoryMaxAbilityReq msg = CrossUnionProto.CrossUnionUpdateHistoryMaxAbilityReq.parseFrom(packet.getBytes());
        for (CrossUnionProto.MemberHistoryMaxAbilityTemp memberHistoryMaxAbilityTemp : msg.getMemberAbilityListList()) {
            CrossUnionMember crossUnionMember = CrossUnionMgr.getUnionMemberByUserId(memberHistoryMaxAbilityTemp.getUserId());
            if(null != crossUnionMember) {
                crossUnionMember.setHistoryMaxAbility(new BigInteger(memberHistoryMaxAbilityTemp.getAbility()));
                CrossUnionMgr.updateUnionTotalMaxAbility(crossUnionMember.getUnionUid());
                if (!StringUtils.isNullOrEmpty(crossUnionMember.getUnionUid())) {//有商会的，换成定时器来同步
                    CrossUnionMgr.addSyncMaxAbilityUnionSet(crossUnionMember.getUnionUid());
                }
            }
        }
    }

    @Override
    public void sendData() {

    }
}
